package cn.jcet.mapreduce.flowsum;

import cn.jcet.mapreduce.bean.FlowBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @author 鲜磊
 * @Date 2020/12/10 22:29
 */
public class ProvincePartitioner extends Partitioner<Text,FlowBean> {
    @Override
    public int getPartition(Text key, FlowBean value, int i) {
        // 转换为字符串，对key进行分割 开闭原则
        String preNum = key.toString().substring(0, 3);
        // 定义分区数
        int partition = 4;
        // 对文件分类做一个分区计算
        if ("136".equals(preNum)){
            partition = 0;
        }else if ("137".equals(preNum)){
            partition = 1;
        }else if ("138".equals(preNum)){
            partition = 2;
        }else if ("139".equals(preNum)){
            partition = 3;
        }
        return partition;
    }
}
